<template>
  <div style="">
    <v-chart
      :forceFit="true"
      :height="height"
      :data="data"
      :scale="scale"
    >
      <v-tooltip
        :showTitle="false"
        dataKey="item*percent"
      />
      <v-axis />
      <v-legend
        dataKey="item"
        position="bottom"
      />
      <v-pie
        position="percent"
        color="item"
        :vStyle="pieStyle"
        :label="labelConfig"
      />
      <v-coord
        type="theta"
        :radius="0.75"
        :innerRadius="0.6"
      />
    </v-chart>
  </div>
</template>

<script>
const DataSet = require('@antv/data-set')



export default {
  name: 'SalesData',
  props: ['sourceData'],
  created() {

    this.scale = [{
      dataKey: 'percent',
      min: 0,
      formatter: '.0%'
    }]
    const dv = new DataSet.View().source(this.sourceData)
    dv.transform({
      type: 'percent',
      field: 'count',
      dimension: 'item',
      as: 'percent'
    })
    this.data = dv.rows
  },
  data() {
    return {
      data: '',
      scale: '',
      height: 385,
      pieStyle: {
        stroke: '#fff',
        lineWidth: 1
      },
      labelConfig: ['percent', {
        formatter: (val, item) => {
          return item.point.item + ': ' + val
        }
      }]
    }
  }
}
</script>

<style scoped>
</style>
